package model.net.handlers
{
	import flash.utils.ByteArray;
	
	import model.net.AbsDataHandler;
	import model.net.NetDataType;

	public class DataSystemHandler extends AbsDataHandler
	{
		public function DataSystemHandler()
		{
			register(NetDataType.SC_SERVER_MESSAGE,recieveServerMsg);
			register(NetDataType.SC_PROMOT_MESSAGE,recieveSystemMsg);
			register(NetDataType.SC_CONFIRM_DIALOG,recieveServerPrompt);
		}
		
		public function recieveServerPrompt(byteArray:ByteArray):void
		{
			var type:int = int(readString(byteArray));
			var content:String = readString(byteArray);
			var id:String = readString(byteArray);
			_model.systeModel.updateServerPrompt(id,content);
		}
		
		public function recieveServerMsg(byteArray:ByteArray):void
		{
			var msgType:int = byteArray.readUnsignedInt();
			_model.netDataParserModel.excute(msgType,byteArray);
		}
		
		public function recieveSystemMsg(byteArray:ByteArray):void
		{
			var promptType:int = byteArray.readShort();
			var sitId:int = byteArray.readShort();
			var content:String = readString(byteArray);
			
			if (promptType == 0)
			{
				_model.tableModel.updateSysMsg(content);
			}
			else if (promptType == 1)
			{
				_model.tableModel.updateChatMsg(content);
			}
			
			if (sitId != -1)
			{
				_model.sitModel.updateSitTalk(sitId,content);
			}
		}
	}
}